import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_reactive_layout_demo/ui/components/reactive_navigation_root_layout.dart';
import 'package:flutter_reactive_layout_demo/ui/pages/artists/artists_page.dart';
import 'package:flutter_reactive_layout_demo/ui/pages/home/home_page.dart';
import 'package:flutter_reactive_layout_demo/ui/pages/playlists/detail/playlist_detail_page.dart';
import 'package:flutter_reactive_layout_demo/ui/pages/playlists/playlists_page.dart';
import 'package:flutter_reactive_layout_demo/ui/pages/test/test_page.dart';

const _pageKey = ValueKey('_pageKey');
const _scaffoldKey = ValueKey('_scaffoldKey');

final appRouter = GoRouter(
    routes: [
      //首页
      GoRoute(
        path: "/",
        pageBuilder: (context, state) => const MaterialPage(
          key: _pageKey,
          child: ReactiveNavigationRootLayout(
            key: _scaffoldKey,
            currentIndex: 0,
            child: HomePage(),
          )
        )
      ),
      //歌曲
      GoRoute(
        path: "/playlists",
        pageBuilder: (context, state) => const MaterialPage(
          key: _pageKey,
          child: ReactiveNavigationRootLayout(
            key: _scaffoldKey,
            currentIndex: 1,
            child: PlaylistsPage(),
          )
        ),
        routes: [
          //歌单详情
          GoRoute(
              path: ":pid",
              pageBuilder: (context, state) {
                String pid = state.pathParameters['pid'] ?? "";
                return MaterialPage(
                    key: state.pageKey,
                    child: ReactiveNavigationRootLayout(
                      key: _scaffoldKey,
                      currentIndex: 1,
                      child: PlaylistDetailPage(pid: pid,),
                    )
                );
              }
          ),
        ]
      ),
      //艺术家
      GoRoute(
          path: "/artists",
          pageBuilder: (context, state) => const MaterialPage(
              key: _pageKey,
              child: ReactiveNavigationRootLayout(
                key: _scaffoldKey,
                currentIndex: 2,
                child: ArtistsPage(),
              )
          )
      ),
      //测试页
      GoRoute(
          path: "/test_page",
          pageBuilder: (context, state) => MaterialPage(
              key: UniqueKey(),
              child: const TestPage(key: ValueKey("test_page"),)
          )
      ),
    ]
);